You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
1.1 KiB

import { z } from "zod";
import { updateItem } from "#server/service/collection";
import { getContextUser } from "#server/utils/context";
const updateSchema = z.object({
title: z.string().optional(),
description: z.string().optional().nullable(),
note: z.string().optional().nullable(),
rating: z.number().min(1).max(5).optional().nullable(),
starred: z.boolean().optional(),
categoryId: z.number().optional().nullable(),
isArchived: z.boolean().optional(),
coverUrl: z.string().optional().nullable(),
url: z.string().optional().nullable(),
aiSummary: z.string().optional().nullable(),
content: z.string().optional().nullable(),
});
export default defineWrappedResponseHandler({ auth: "required" }, async (event) => {
const user = getContextUser(event)!;
const id = parseInt(event.context.params!.id);
const body = await readBody(event);
const parsed = updateSchema.safeParse(body);
if (!parsed.success) return R.error("参数校验失败", parsed.error.issues);
const updated = await updateItem(id, user.id, parsed.data);
if (!updated) return R.error("收藏不存在", null);
return R.success(updated);
});